package sivan.mybatis;

import org.apache.ibatis.type.JdbcType;

import java.util.HashMap;
import java.util.Map;

public class MyTypeHandlerFactory {
    private final Map<JdbcType, TypeHandler<?>> map = new HashMap<>();
    private final TypeHandler<?> DEFAULT_HANDLER;

    public MyTypeHandlerFactory() {
        DEFAULT_HANDLER = new ObjectTypeHandler();
        map.put(JdbcType.INTEGER, new IntegerHandler());
        map.put(JdbcType.VARCHAR, new StringHandler());
    }

    public TypeHandler<?> getHandler(JdbcType jdbcType) {
        return map.getOrDefault(jdbcType, DEFAULT_HANDLER);
    }
}
